Component Overview

General Info

Help file for Delphi GridView 1.8.5

This is a BETA version of GridView help, and we planing to update this help constantly.

See Also: Installing , License , Tutorials , Reference


Component Overview

Overview

GridView is a component for storing, managing and displaying custom data in grid or slide style.

Articles
Installing component
Beta version limitations
Component Tutorials

Features
Handling large amount of cells in real time
Quick, smart and easy to use sorting of columns
Input line for quick input

Handling large amount of cells in real time

GridView can handle very large amount of cells without losing speed. Speed of adding, modifying and deleting data does 't depend of the amount of cells.

Quick, smart and easy to use sorting of columns

GridView using modification of QuickSort sorting algorithm. QuickSort algorithm in GridView is modified to fork fast with arranged arrays.

User can sort columns by clicking on column header or setting property Sorted to true. Also you can set sort kind with property SortKind.

Input line for quick input

Below Header GridView have Input area where user can simply add new row in grid without using TEdit controls and dialogs. User just need to input data in this area and then to press Enter to to click somewhere on grid. In that moment grid will have new row with data from Input area.

To show Input you need to turn goInput flag in Options property.


Installing of Component

License agreement

This component is freeware and can be used in commercial programs without registration. The software is provided "as-is" without any express or implied warranty. Redistribution of any of the software's files is strictly prohibited without express written permission of the owner.

See Also: Overview , License , Tutorials , Reference


Installing of Component

Installing

Follow this steps to install component. It is very IMPORTANT to follow the procedure in CORRECT order.

  1. Unzip archive into desired folder (example: c:\Components) and you will get one new folder named "Berg"
  2. Run Delphi
  3. Click on Tools -> Environment Options -> Library
  4. Add path to sub folder named "source" and path to sub folder named "source" in GridView sub-folder.
    For example: C:\Components\Berg\source, C:\Components\Berg\source\gridview
  5. Click on File -> Open
  6. Open all packages from "packages" folder then Compile and Install packages in THIS ORDER
    1. common_run
    2. gridview_run
    3. gridview_dsgn
  7. Close all packages. If Delphi ask to save, choose NO

If you have some questions please email us on support@bergsoftware.net

See Also: Overview , License , Tutorials , Reference


Working with component

Beta Version Information

Please read following text if you want to see current status of component.

This component is currently in BETA stage. Some behaviors are not completely implemented and some of properties and methods missing. We plan to improve component constantly. In this stage component is very functional.

You can add/insert/modify/ columns and rows without any limitations.

Here is a list of incomplete parts in component:

Status | Description
 | ColumnsEditor don't refresh when user change some of column properties. You need to close -> open columns editor.
done | Currently user can't edit cells with Inplace editors.
 | AutoSize property is not completely implemented.
 | Column formulas are not completely implemented. We suggest not using this feature yet.
 | Multi selection
 | XP version of component
 | Inplace editors for all column classes

See Also: Overview , License , Installing , Reference


Class Reference

Reference

GridView constist of following classes:

Classes
TCustomColumn
TColumns
TCustomGridView
TGridView

GridView constist of following types:

Types
TCellColoringEvent
TCellState
TChangeCellEvent
TColumnOptions
TCustomDrawCellEvent


TColumns class

TColumns

Unit:
Columns

TComponent
|
TColumns

This class provides common properties and methods (such as paint methods) for TGridView class.

Properties
ClientWidth
Count
Item
PositionItem
VisibleCount

Methods
Add
ChangePosition
Clear
Delete
Insert
Move

property Count: Integer;

This property return numbers of rows in grid. This is a read-only property.

function Add(ColumnClass: TColumnClass): TCustomColumn;

This function add new column, and return a reference of this column.

ColumnClass parameter determine column kind.

procedure ChangePosition(CurPosition, NewPosition: Integer);

This metod change position of column with position = CurPosition to NewPosition.

Position of column can be changed with TCustomColumn.Position property.

procedure Clear;

Clear all columns in GridView.

procedure Delete(Index: Integer);

Delete column with specified Index. Index parameter is zero-based. If you want to hide column insted of deleting it use TCustomColumn.Visible property.

procedure Insert(ColumnClass: TColumnClass; Pos: Integer);

Insert new column at specified position in Items array.

ColumnClass parameter determine column kind.


TCustomColumn class

TCustomColumn

Unit:
Columns

TComponent
|
TCustomColumn

This is a base class for all columns.

Properties
Alignment
Color
DrawingOptions
Index
Options
Position

property Alignment: TAlignment;

Specifies how data is aligned within a column.

The following are possible values of TAlignment: taLeftJustify, taCenter, taRightJustify.

property Color: TColor;

Determine Column's color. Each cell in column will be painted in Color specified with this property.

property DrawingOptions: TDrawingOptions;

Specify how column will be rendered.

If you set this property to doCustom you will be able to make additional drawing on each cell using OnCustomDrawCell event.

property Index: Integer;

Determine Index of Column in Columns ARRAY. To access to Column properties and methods use Columns.Items[Index] or shorter Columns[Index].

property Options: TColumnOptions;

This property specifying common column behaviors.

property Position: Integer;

This property determine column drawing position in component. Note that position is not Index of column.

Position can be changed in run-time by draging column header.


TCustomGridView class

TCustomGridView

Unit:
CustomGridView

TCustomControl
|
TScrollView
|
TCustomGridViewControl
|
TCustomGridView

This class provides common properties and methods (such as paint methods) for TGridView class.

Properties
Cells

Methods (Protected)
GetCells
SetCells

Methods
AddRow
AddRowFromInputLine

property Cells[ACol, ARow: Integer]: string;

This property read or set value into cell specified with ACol and ARow. ACol must be between 0 and Columns.Count - 1. ARow must be between 0 and RowCount - 1.

procedure AddRow(Count: Integer = 1);

This method add row at the end of grid. You may specify Count > 1 for adding multiple rows at same time.

procedure AddRowFromInputLine;

This method manualy add row at the end of grid using InputValue propertiy from each Column.


TCustomGridViewControl class

TCustomGridViewControl

Unit:
CustomGridViewControl

TCustomControl
|
TScrollView
|
TCustomGridViewControl

This class provides common properties and methods (such as paint methods) for TGridView class.

Properties
Caption
Columns
Options
RowCount
RowSize
SelectedColumn
SelectedRow

Events
OnCellColoring
OnChangeCell
OnCustomDrawCell
OnHeaderClick
OnInputAccept

property Caption: TCaption;

This property is used for displaying custom text when there is no rows in grid.

For example here you can set: There is no items to show in this View.

property Columns: TColumns;

This property is used for adding, deleting, changing... columns in grid.

To open Column editor click on button with ... beside property in Object Inspector, or double-click on component. See also TColumns reference.

property Options: TGridOptions;

This property determine how GridView will look and act.

With this property you can show or hide some of component parts like a Header, Footer...

property RowCount: Integer;

This property return numbers of rows in grid. This is a read-only property.

property RowSize: Integer;

Determine size of Row when GridStyle = gsReport.

property SelectedColumn: Integer;

Determine currently selected column in grid. This value can be only between from 0 to Columns.Count - 1.

property SelectedRow: Integer;

Determine currently selected row in grid. This value can be between from 0 to RowCount - 1.

property OnCellColoring: TCellColoringEvent;

This event occur when cell need to determine background color, and grid line color.

With this event you can additionaly to set color for each cell.

property OnChangeCell: TChangeCellEvent;

This event occur when user change cell in grid with mouse, keyboard or in code.

property OnCustomDrawCell: TCustomDrawCellEvent;

This event occur when Column is in drawinng progress and have property DrawingOptions is doCustom.

property OnHeaderClick: THeaderClickEvent;

This event occur when User click on Column's header.

property OnInputAccept: TInputAcceptEvent;

This event occur when User has finished with inputing text in Input Line.

In this event you can decide to accept or not input from Input Line.


TGridView class

TDBGridView

Unit:
DBGridView

TCustomControl
|
TScrollView
|
TCustomGridViewControl
|
TCustomGridView
|
 TGridView
 |
TDBGridView

This is the main class in component.

Properties (published)
DataAvareOptions
DataSource

Methods
AddRow
ClearRows
DeleteRow
InsertRow

property DataAvareOptions: TDataAwareOptions;

Settings used for customizing work with DataSet.

property DataSource: TDataSource;

Identifies the link to the dataset where the data-aware grid finds its data.

Set DataSource to the TDataSource object that links to the dataset where the component should fetch its data. DataSource allows the data-aware grid to read from, write to, and navigate around the dataset.

procedure AddRow(Count: Integer = 1);

Add specified number of new record on end of DataSet (TTable, TADOTable...). This method don't work on unidirectional and read-only data set's (TQuery).

procedure ClearRows;

Clear all records from DataSet (TTable, TADOTable...). This method don't work on unidirectional and read-only data set's (TQuery).

procedure DeleteRow(ARow: Integer);

Delete specified record from DataSet (TTable, TADOTable...). This method don't work on unidirectional and read-only data set's (TQuery).

procedure InsertRow(Pos: Integer);

Insert new record at specified position in DataSet (TTable, TADOTable...). This method don't work on unidirectional and read-only data set's (TQuery).


TGridView class

TGridView

Unit:
GridView

TCustomControl
|
TScrollView
|
TCustomGridViewControl
|
TCustomGridView
|
TGridView

This is the main class in component.

Properties (published)
Caption
Columns
GridStyle
Images
Options
RowSize
SelectedColumn
SelectedRow

Methods
AddRow
AddRowFromInputLine
ClearRows
DeleteRow
InsertRow
MoveRow

Methods (Protected)
PaintReportParts
PaintReportRows
PaintSlideRows


TCustomColumn class

TCheckBoxColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TCheckBoxColumn

[documentation is not ready yet]


TCustomColumn class

TImageColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TImageColumn

This is a column who display data as image. Image can be loaded from disk, or can be used from ImageList.

Properties
ImageSourceKind

property ImageSourceKind: TImageSourceKind;

This property determine Image source (disk or ImageList).

For Example:

For using images from attached ImageList (ImageSourceKind := isImageIndex) values in cells must represent Image Indexes:

For using images from disk (ImageSourceKind := isFileName) values in cells must represent full File Names:


TCustomColumn class

TIncrementColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TIncrementColumn

[documentation is not ready yet]


TCustomColumn class

TProgressColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TProgressColumn

[documentation is not ready yet]


TCustomColumn class

TRateColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TRateColumn

[documentation is not ready yet]


TCustomColumn class

TTextualColumn

Unit:
ColumnClasses

TComponent
|
TCustomColumn
|
TTextualColumn

This is a column who display data in text (string) format.

Properties
AutoExecute
TextAfter
TextBefore

property AutoExecute: Boolean;

When this property is set to True each cell in column will be Hyperlink.

property TextAfter: TCaption;

Text from this property will be added AFTER cell text in each cell in column. Note that original text will be not changed.

property TextBefore: TCaption;

Text from this property will be added BEFORE cell text in each cell in column. Note that original text will be not changed.


TCustomColumn class

TDBTextualColumn

Unit:
DBColumns

TComponent
|
TCustomColumn
|
TTextualColumn
|
TDBTextualColumn

This is a column who display data in text (string) format.

Properties
FieldName

property FieldName: string;

Indicates the name of the field represented by the column.

Setting FieldName point to the dataset field with the same name. If the dataset does not have a field with the same name column will be empty.


TCellColoringEvent type

TCellColoringEvent

Unit:
CustomGridViewControl

type TCellColoringEvent = procedure (Sender: TObject; ACol, ARow: Integer; var CellColor, GridColor: TColor; CellState: TCellState) of object;

The following are parametres of TCellColoringEvent:

Parameter | Meaning
CellColor | Represent background color of cell. This is a var parameter and can be changed within event.
GridColor | Represent grid line color of cell. This is a var parameter and can be changed within event.
CellState | Represent state of cell.


TCellState type

TCellState

Unit:
CustomGridViewControl

type TCellState = set of (csFocused, csSelected);

TCellState consists of a set of flags used from the following values:

Value | Meaning
csFocused | Cell is focused. Cell having keyboard focus.
csSelected | Cell is selected.


TChangeCellEvent type

TChangeCellEvent

Unit:
CustomGridViewControl

type TChangeCellEvent = procedure (Sender: TObject; ACol, ARow: Integer) of object;

The following are parametres of TChangeCellEvent:

Parameter | Meaning
ACol | Represent index of new selected column.
ARow | Represent index of new selected row.


TGridOptions type

TColumnOptions

Unit:
Columns

type TColumnOptions = set of (coAutoSize, coCanClick, coCanSort, coDontHighlight, coEditing, coEditorAutoSelect, coFixedSize, coImageForIcon, coPublicUsing, coSearchColumn, coTextForCaption);

TColumnOptions consists of a set of flags used from the following values:

Value | Meaning
coAutoSize | Column will be auto-sized when user resize component or other columns.
coCanClick | User can click on column's header.
coCanSort | Column can be sorted.
coDontHighlight | Cells in this column will not be highlighted when cell is selected.
coEditing | Column can be edited.
coEditorAutoSelect | Cell Editor will be auto selected in edit mode.
coFixedSize | Column can't be resized.
coImageForIcon* | in gsIcon GridStyle this column (only TImageColumn) will be used for displaying Icon.
coPublicUsing | Column will be processed with CellSource descendants.
coSearchColumn | Column will be used for run-time searching (type and search next)
coTextForCaption* | in gsIcon GridStyle this column (only TTextualColumn) will be used for displaying text.

*Not implemented


TCustomDrawCellEvent type

TCustomDrawCellEvent

Unit:
CustomGridViewControl

type TCustomDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Integer; CellRect: TRect; CellState: TCellState) of object;

The following are parametres of TCustomDrawCellEvent:

Parameter | Meaning
CellRect | Represent client rect of cell. This rect is relative to Grid.
CellState | Represent state of cell.


TDrawingOptions type

TDrawingOptions

Unit:
CustomGridViewControl

type TDrawingOptions = (doNormal, doCustom);

The following are possible values of TDrawingOptions:

Value | Meaning
doNormal | Default drawing.
doCustom | Drawing with using of OnCustomDrawCell event.


TGridOptions type

TGridOptions

Unit:
CustomGridViewControl

type TGridOptions = set of (goAlwaysShowSelection, goCanHideColumn, goFooter, goGrid, goHeader, goIndicator, goInput, goOnlyHorzGridLines, goSelectFullRow, goHighlightTextSelection);

TGridOptions consists of a set of flags used from the following values:

Value | Meaning
goAlwaysShowSelection | Selection will be always showed. Even if Grid lost focus.
goCanHideColumn | When this flag is set, user can drag column header outside header line to hide column.
goFooter | Show Footer.
goGrid | Show Grid Lines.
goHeader | Show Header.
goIndicator | Show Indicator.
goInput | Show Input Line.
goOnlyHorzGridLines | Show only horizontal Grid Lines.
goSelectFullRow | When user click on single cell the entire row will be selected.
goHighlightTextSelection | Text in selected cell will be in clHighlight color.

*Not yet implemented


THeaderClickEvent type

THeaderClickEvent

Unit:
CustomGridViewControl

type THeaderClickEvent = procedure (Sender: TObject; ACol: Integer) of object;

The following are parametres of THeaderClickEvent:

Parameter | Meaning
ACol | Represent Column Index for clicked Header.


TInputAcceptEvent type

TInputAcceptEvent

Unit:
CustomGridViewControl

type TInputAcceptEvent = procedure (Sender: TObject; var Accept: Boolean) of object;

The following are parametres of TInputAcceptEvent:

Parameter | Meaning
Accept | This parameter can be changed to forbide input from Input Line. Default value is True.


TSlideBounds

Unit:
Columns

TPersistent
|
TSlideBounds

This is a column who display data in text (string) format.

Properties
Height
Left
Top
Width

property Height: Integer;


TCellState type

TSortKind

Unit:
Columns

type TSortKind = (skAscending, skDescending);

The following are possible values of TSortKind:

Value | Meaning
skAscending | Column will be sorted in Ascending order.
skDescending | Column will be sorted in Descending order.


Component Overview

Tutorials

Click on tutorial to read it:

Tutorials
Introducing GridView
Working with columns
Working with rows
Using Slides


Working with component

Introducing GridView

Articles
Parts of GridView
Customize component
Adding columns

Parts of GridView

On next image you may see all GridView parts:

Customize component

For start is best to use Options property. With this property you can show/hide some of grid parts or to turn on/off some behaviors.

To display grid lines in grid you need to turn on goGrid flag.

Options := Options + [goGrid];

If you want to show only horizontal grid lines you need to turn goOnlyHorzGridLines flag. Note that this flag must be combinet with goGrid flag.

Options := Options + [goOnlyHorzGridLines];

Adding columns

Now we need to add some columns into component. Click here to learn how to work with columns.

See Also: Overview , License , Installing , Reference


Working with component

Working with Columns

Articles
How to start
Working with Header (Title)
Customizing column

How to start

Before start to work with columns, we need to see all Column's parts:

Mark | Name | Description
1 | Column's Header | Title of column. User can click here to sort Column.
2 | Column's Input | User can type text here to quickly add new row.
3 | Column's Cells | Column's data.
4 | Column's Footer | Ideal place for displaying column's calculations.

To start to work with columns Double-click on component or click on ... buttons beside Columns property in Object Inspector. Also you can right-click on control and to choose Columns Editor from pop-up menu.

Now you will see a Column Editor where you can to add, delete or modify columns.

If you click on some button in first group of toolbar items, you will add one column to GridView.

You can choose wich column type you want to add. Each column type (Column Class) display data in different way.

If you want to add column in Run-Time you can use:

function Columns.Add(ColumnClass: TColumnClass): TCustomColumn;
procedure Columns.Insert(ColumnClass: TColumnClass; Pos: Integer);

When you have added column, select this column in editor to change properties.

Working with Header (Title)

To set title text for column use Caption property:

property Columns[Index].Header.Caption: TCaption;

To set image for column's title set Glyph property:

property Columns[Index].Header.Glyph: TBitmap;

But if you want to display Image in column's title you need to set DisplayMode to:

Value | Meaning
dmImageOnly | Display Image and ignore Caption
dmTextAndImage | Display both Image and text in Caption.

Customizing column

To change column's Color specify Color property.

To align Data horizontaly in column specify Alignment property.

See Also: Overview , License , Installing , Reference


Working with component

Working with Rows

Articles
Adding Rows
Modifying Rows
Example

Adding Rows

If you have finished with adding Columns you can start with adding rows. You need to have at least one column to start with adding Rows.

To add one or multiple rows at the end of grid use:

procedure AddRow(Count: Integer = 1);

Example:

AddRow; // Add one row
AddRow(3); // Add 3 rows

To Insert row at specified position use:

procedure InsertRow(Pos: Integer);

Example:

InsertRow(7); // Insert one row at position 7 and shift all rows after position 7

Modifying Rows

To move row to the new position use following method:

procedure MoveRow(FromPos, ToPos: Integer);

Example:

MoveRow(5, 8); // Move row from position 5 to position 8

To delete single row from the grid use:

procedure DeleteRow(ARow: Integer);

Example:

DeleteRow(26); // Delete row from position 26

To Clear all cells in grid (delete all rows) use:

procedure ClearRows;

Note that this method will not erase columns.

Example

In next example we will create simple grid for displaying employers in one company:

  1. Drop one TGridView component into blank Form.
  2. Name this component: MyGrid
  3. Double click on Form and insert following code:

implementation

uses
  ColumnClasses; // You need to add this unit in uses section to work with columns in run-time

// First we need to add 3 columns
// If you want you can skip this part of code and to add columns with columns editor by double-clicking on component

MyGrid.Columns.Add(TCheckBoxColumn); // We will have one checkbox column for determining employee avaiability
MyGrid.Columns.Add(TTextualColumn); // Add one textual column for First Name
MyGrid.Columns.Add(TTextualColumn); // One more column for Last Name

// Now we will modify theese columns
MyGrid.Columns[0].Header.Caption := 'In Office'; // Set title for first column

// Cells with value 'yes' will be checked checkbox
TCheckBoxColumn(MyGrid.Columns[0]).CheckedText := 'yes';

// Cells with value 'no' will be unchecked checkbox
TCheckBoxColumn(MyGrid.Columns[0]).UnCheckedText := 'no';

MyGrid.Columns[1].Header.Caption := 'First Name';
MyGrid.Columns[2].Header.Caption := 'Last Name';

// Now we will start with adding rows
MyGrid.AddRow(3); // Add 3 rows

// Setting cells for first column
MyGrid.Cells[0, 0] := 'yes';
MyGrid.Cells[0, 1] := 'yes';
MyGrid.Cells[0, 2] := 'yes';

// Setting cells for second column
MyGrid.Cells[1, 0] := 'John';
MyGrid.Cells[1, 1] := 'Mike';
MyGrid.Cells[1, 2] := 'Steele';

// Setting cells for third column
MyGrid.Cells[2, 0] := 'McCoy';
MyGrid.Cells[2, 1] := 'Sharp';
MyGrid.Cells[2, 2] := 'Sampson';

See Also: Overview , License , Installing , Reference


Using Slides

Articles
Overview
Setting Slide Bounds

Overview

In GridView you don't need to display data only in table like form.

You can also to display Data in Slide like form.

Note that all styles share data.

To switch GridView to display slides we need to set GridStyle property to gsSlides in Object Inspector or in Run-Time:

property GridStyle: TGridStyle;

Setting Slide Bounds

For best result we we need to set SlideBounds property for each column:

property Columns[Index].SlideBounds: TSlideBounds;

In this property we need to set cell position (relative to CURRENT slide row) and size (Width and Height).

Example:

For more details see demo project.

See Also: Overview , License , Installing , Reference